|
|
|
|
|
|
|
action places a new blank form on the screen. This form looks just like your first form initially did. If you did not rename your first form from the default of Form1, the new form is named Form2 (or Form3, Form4, and so on). Otherwise, the new form is named Form1. |
|
|
|
|
| |
|
|
|
|
You can add files, forms, or modules from a pop-up menu by right-clicking within the Project window. |
|
|
|
|
|
|
|
|
|
|
After you add a new form, you can place controls on it and write code for its events, just like for the initial form. You also need to be able to access the new form from other forms in your program. Access is handled through the Load and Unload statements and the Show and Hide methods of the form object. |
|
|
|
|
|
|
|
|
See "Displaying a Form," p. 55 |
|
|
|
|
|
|
|
|
Adding Code Modules to a Project |
|
|
|
|
|
|
|
|
As you write more code to handle more events and more tasks, you may often find that you need to access the same procedure from a number of different places on a form or from multiple forms. If this is the case, storing the procedure in a module file makes sense. |
|
|
|
|
| |
|
|
|
|
If you have a library of common functions, such as printing routines, keep them in a separate module file so that you can easily add the library to different projects. |
|
|
|
|
|
|
|
|
|
|
Again, a module file contains only Visual Basic code; it does not contain any controls, graphics, or other visual information. When you want to add a module file to hold your procedures, you can do so either by clicking the arrow on the Add Form button and choosing Module from the drop-down menu, or by choosing Project, Add Module. Either of these actions adds a new module to your project and places you in the Code window for the module (see Figure 11.6). |
|
|
|
|
|
|
|
|
When you first open a new module, Visual Basic gives it the default name of Module1 (or Module2 for a second module, and so on). As you do with your forms and controls, you should give the module a unique name. The module has a Name property, just as a form does. To change the name of the module, simply change the value of the Name property in the Property window. |
|
|
|
|
|
|
|
|
Accessing the Forms and Modules of a Project |
|
|
|
|
|
|
|
|
As you add forms and modules to your program, they are added to the Project window. This window allows you to access any of the pieces of your program easily (see Figure 11.7). You simply select a form or module by clicking its name in the Project window. For a form, you can then click the View Object button to work on the design of the form, or you can click the View Code button to edit the code associated with the form. For a module, only the View Code button is enabled because a module has no visual elements. Double-clicking the name of a form has the same effect as clicking the View Object button. Double-clicking a module name has the same effect as clicking the View Code button. |
|
|
|
|
|